/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.File;
import java.util.UUID;

/**
 * <p>Project: jse2302 - Ex4
 * <p>Powered by webrx On 2023-06-20 09:08:59
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex4 {
    public static void main(String[] args) {
        String file = "c:/users/crm/uploads/230620/us*r_abcxxx234.jpg";
        //file = "c:\\users\\crm\\uploads\\230620\\usr_abc.jpg";

        System.out.println(file);

        //File ff = new File(file);
        //System.out.println(ff.getAbsolutePath());

        //取文件目录
        if(file.contains("/")) {
            System.out.println(file.substring(0, file.lastIndexOf("/")));
        }else{
            System.out.println(file.substring(0, file.lastIndexOf("\\")));
        }

        //取出文件名
        String filename = file.substring(file.lastIndexOf("/")+1);
        System.out.println(filename);
        System.out.println(filename.substring(0,filename.lastIndexOf(".")));
        System.out.println(filename.lastIndexOf(".")!=-1 ? filename.substring(filename.lastIndexOf(".")+1):"");

        System.out.println();

        String newfilename = file.substring(0, file.lastIndexOf("/")) +"/" + UUID.randomUUID() + (filename.lastIndexOf(".")!=-1 ? filename.substring(filename.lastIndexOf(".")):"");
        System.out.println(newfilename);


    }
}
